#include "comm.hpp"

int main()
{
    // 创建管道文件
    if (mkfifo(ipcPath.c_str(), MODE) < 0)
    {
        perror("mkfifo");
        exit(1);
    }

    // 打开文件
    int fd = open(ipcPath.c_str(), O_RDONLY);
    if (fd < 0)
    {
        perror("open");
        exit(2);
    }

    // 进行通信操作
    char buffer[SIZE];
    while (true)
    {
        ssize_t s = read(fd, buffer, sizeof(buffer) - 1);
        if (s > 0)
        {
            buffer[s]='\0';
            cout << "client say: " << buffer << endl;
        }
        else if (s == 0)
        {
            cerr << "read end of file, client quit, server quit too!" << endl;
            break;
        }
        else
        {
            perror("read");
            break;
        }
    }

    // 关闭文件描述符
    close(fd);
    unlink(ipcPath.c_str());
    return 0;
}